package io.github.iogogogo.api;

import io.github.iogogogo.commons.util.DateTimeUtils;
import io.github.iogogogo.web.WebBaseApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Created by tao.zeng on 2024/11/15.
 */
@RestController
@RequestMapping("/api/knife4j")
@Tag(name = "body参数")
public class IndexApi implements WebBaseApi {

    @Operation(summary = "普通body请求")
    @PostMapping("/body")
    public ResponseEntity<Map<String, Object>> body(@RequestBody Map<String, Object> body) {
        body.put("timestamp", DateTimeUtils.nowDateTime());
        return ResponseEntity.ok(body);
    }

    @Operation(summary = "普通body请求+Param+Header+Path")
    @Parameters({
            @Parameter(name = "id", description = "文件id", in = ParameterIn.PATH),
            @Parameter(name = "token", description = "请求token", required = true, in = ParameterIn.HEADER),
            @Parameter(name = "name", description = "文件名称", required = true, in = ParameterIn.QUERY)
    })
    @PostMapping("/bodyParamHeaderPath/{id}")
    public ResponseEntity<Map<String, Object>> bodyParamHeaderPath(@PathVariable("id") String id, @RequestHeader("token") String token, @RequestParam("name") String name, @RequestBody Map<String, Object> body) {
        body.put("receiveName", name);
        body.put("token", token);
        body.put("pathID", id);
        body.put("timestamp", DateTimeUtils.nowDateTime());
        return ResponseEntity.ok(body);
    }
}
